import {observable} from 'mobx';
import {Tools,Bubble} from 'weaver-mobile';
import { ListPage,SearchAdvanced,ListAdvanced } from 'weaver-mobile-page';
import * as API from '../../api/home';

const getLabel = Tools.getLabel;

export default class WalletStore {
    /********************************************************/
    @observable loading = false;
    @observable hasRight = false;

    @observable tabs = [];
    @observable tabVisible = true;
    // @observable tabPage = [];
    @observable selectKey = 0; //顶部tab key
 
    @observable listAd = new ListAdvanced.Store({ route: '/apply', id: 'advance' });
    @observable upCompingList = new ListPage.Store();

    @observable leftParams = {};
    @observable workflowSelect = [];

    initStore = (value)=>{
        this.search = new SearchAdvanced.Store({ route:value});
    }

    getTab = (value={}) =>{
        this.tabs = [{ title: getLabel(16349,'待处理') },{ title: getLabel(1210,'我的请求') }];
        // this.getUpComingAll(value);     
    }

    //获取待办事项
    getUpComingAll = (value={}) =>{
        this.loading = true;
        API.getUpComingAll(value).then( res =>{
            let {status,upCompingList} = res;
            if(status === '1'){
                if(upCompingList){
                    this.upCompingList.setState(upCompingList); 
                }else{
                    this.upCompingList = new ListPage.Store();
                }
               
                
            }else{
                console.log('异常')
            }
            
            this.loading = false;
        }) 
    } 

    //获取 报销流程 选项
    getInvoiceCreatWorkflow = (value={},callBack) =>{
        // this.loading = true;
        API.getInvoiceCreatWorkflow(value).then( res =>{
            const {status,workflowSelect} = res;
            if(status == '1'){
                this.workflowSelect = workflowSelect;
                // callBack && callBack({workflowSelect:workflowSelect});
            }else{
                Bubble.error(res.errorInfo)
            }

            // this.loading = false;
        })
    }

    //发起流程
    invoiceCreatWorkflow = (value,callBack) =>{
        this.loading = true;
        API.invoiceCreatWorkflow(value).then( res =>{
            const {status,workflowSelect} = res;
            if(status == '1'){
                callBack && callBack({
                    requestId:res.requestId
                })
            }else{
                Bubble.error(res.errorInfo)
            }

            this.loading = false;
        })
    } 

    
    setSelectKey = (value) =>{
        this.selectKey = value;
    }

    //设置顶部是否可见
    setTabVisible = (value) =>{
        this.tabVisible = value;
    }

    //存储 左侧树参数
    setLeftParams = (value) =>{
        this.leftParams = value;
    }

    clearData = () =>{
        this.selectKey = 0;
        this.tabVisible = true;
        this.leftParams = {};
    }

}